package com.distribution.common.web.handler;

import com.distribution.common.exception.RepeatSubmitException;
import com.distribution.common.web.response.ResponseResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author test
 * @date 2022年01月03日 22:12
 */

@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(RepeatSubmitException.class)
    public ResponseEntity RepeatSubmitExceptionHandler(RepeatSubmitException ex){
        ResponseResult responseResult = new ResponseResult(400,ex.getMessage());
        ResponseEntity entity = new ResponseEntity(responseResult,HttpStatus.BAD_REQUEST);
        return entity;
    }

    @ExceptionHandler(Exception.class)
    public String exceptionHanlder(Exception ex){
        return ex.getMessage();
    }
}
